import {ActModel} from "../../../models/ActModel.js"
const _ActModel = new ActModel();
const app = getApp();
var _self ;

Page({
  data: {
    actDetailInfo:null,
    actId:"",
    hasSignList:[],
    actFrom:"",
    maxImageNumber:0
  },
  initPhotoNumber:function(){
    let width = app.globalData.windowWidth;
    let result = (width * (750 / width))-40; 
    let num = Math.floor(result/78)
    _self.setData({
      maxImageNumber:num
    })
  },
  onLoad: function (options) {
    _self = this;
    if(options){
      _self.setData({
        actId: options.act_id,
        actFrom:options.from
      })
    }
   _self.initPhotoNumber(); 
    _ActModel.setView(options.act_id);
    _ActModel.getDetail(options.act_id,function(data){
     _self.setData(
       {
         actDetailInfo:data[0]
       }
     )
    });
    _ActModel.getSignList(options.act_id, function (data) {
      if (data.length > _self.data.maxImageNumber){
        data = data.slice(0, _self.data.maxImageNumber);
         }
        let tempArr = []
        for (let i = 0; i < data.length; i++) {
          tempArr.push(data[i].profileUrl)
        }
        _self.setData({
          hasSignList: tempArr
        })
    });
    
  },
  changeData(){
    _ActModel.getDetail(_self.data.actId, function (data) {
      _self.setData(
        {
          actDetailInfo: data[0]
        }
      )
    });
  },
  onReady: function () {

  },
  onShareAppMessage: function () {

  },
  signup:function(){
    _ActModel.signUp(this.data.actId,function(){
        wx.showToast({
          title: '报名成功',
          icon: 'success',
          duration: 3000,
          success:function(){
            
          }
        })
      })
  },
  gotoSignedList:function(){
    wx.navigateTo({
      url: '/pages/activity/enroll/enroll?actId=' + _self.data.actId + "&from=" + _self.data.actFrom
    })
  },
  editAct:function(){
    wx.navigateTo({
      url: '/pages/activity/Initiating/Initiating?actId=' + _self.data.actId + "&type=edit&from=" + _self.data.actFrom
    })
  }
})